//新零售内循环，ITEMLIST其中一个为45 Trait BP/SB
//新零售1开始时间小于等于新零售2结束时间，新零售1开始时间大于等于新零售2开始时间
//新零售1结束时间小于等于新零售2结束时间
//S2<=S1<=E2  E1<=E2
//新零售1大于新零售2

var result_91_5 = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"", "MSG":"","DATA":"","RULE":"FS_91_5"}');
var JSON_LINKSAVE = !isNull(LINKSAVE) ? JSON.parse(LINKSAVE) : [];

function RisePrice(TRAIT_STORE_NBR, RETAIL_TYPE, JSON_ITEM_LIST) {
    for (var i = 0; i < JSON_ITEM_LIST.length; i++) {
        var S2 = new Date(JSON_ITEM_LIST[i].EFFECTIVE_DATE);
        var E2 = new Date(JSON_ITEM_LIST[i].EXPIRATION_DATE);
        if (JSON_ITEM_LIST[i].TRAIT_STORE_NBR == 45
            && (JSON_ITEM_LIST[i].RETAIL_TYPE == 'BP' || JSON_ITEM_LIST[i].RETAIL_TYPE == 'SB')
            && (RETAIL_TYPE == 'BP' || RETAIL_TYPE == 'SB')
            && betweenDay(S2, EFF_DATE) >= 0 && betweenDay(EFF_DATE, E2) >= 0 && betweenDay(EXP_DATE, E2) > 0
            && NEW_RETAIL > JSON_ITEM_LIST[i].NEW_RETAIL) {
            return true;
        }
    }
    return false;
}

if (!isNull(UPC_NBR) && UPC_NBR.toString().substr(0, 2) == '21') {
    if (!isNull(LINKSAVE)
        && !inSuspendBP(ITEM_NBR, NEW_RETAIL_EFF_DATE, JSON_ITEM_LIST, ID, RETAIL_TYPE)
        && RisePrice(TRAIT_STORE_NBR, RETAIL_TYPE, JSON_ITEM_LIST)
        && LinkSaveRisePriceBPSB(JSON_LINKSAVE, RETAIL_TYPE, EFF_DATE, EXP_DATE)) {
        result_91_5.CODE = 1;
        result_91_5.ACTION = "APPROVAL_LEVEL";
        result_91_5.LEVEL = "AG";
        result_91_5.MSG = "与Linksave冲突的高风险变价，需GMM审批";
    }
}
JSON.stringify(result_91_5);


